****** Collapse & Expand ******
*** 31082023 ***
REPORT CollapseExpand.
TYPE-POOLS icon.
TABLES mara.
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME.
PARAMETERS P_WERKS TYPE WERKS_D.
SELECTION-SCREEN END OF BLOCK B1.

SELECTION-SCREEN SKIP 1.

SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN PUSHBUTTON 1(4) BUT1 USER-COMMAND BUTTON1 VISIBLE LENGTH 2.
SELECTION-SCREEN COMMENT 6(20) COM1.
SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN BEGIN OF BLOCK B2 WITH FRAME.
SELECT-OPTIIONS: S_MATNR FOR MARA-MATNR MODIF ID BL1,
S_GROES FOR MARA-GROES MODIF ID BL1.
SELECTION-SCREEN END OF BLOCK B2.

INITIALIZATION.
WRITE ICON_DATA_AREA_EXPAND AS ICON TO BUT1.
COM1 = 'Data Collapse'.

AT SELECTION-SCREEN.
CASE SY-UCOMM.
    WHEN 'BUTTON1'.
        IF BUT1 = '@K1@'.
            WRITE ICON_DATA_AREA_COLLAPSE AS ICON TO BUT1.
            COM1 = 'Data Expand'.
        ELSE.
            WRITE ICON_DATA_AREA_EXPAND AS ICON TO BUT1.
            COM1 = 'Data Collapse'.
        ENDIF.
    WHEN OTHERS.
ENDCASE.

LOOP AT SCREEN.
IF but1 = '@K2@' AND screen-group1 = 'BL1'.
    screen-active = 0.
    MODIFY SCREEN.
ENDIF.
ENDLOOP.